/**
 * http的工具类
 * @author 冯永泽
 * @date 2019/12/3
 */

const request = require('request');
class http {
    constructor(hostName) {
        // this.access_token = global.access_token || ''
        this.hostName = hostName;
        this.headers = {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'accessToken': ''
        };
    }
    /**
     * post请求
     * @param {Object} content 请求参数
     * @param {Function} postFunction 回调方法
     */
    post(content, postFunction) {
        if(content.access_token){
            this.headers.accessToken = content.access_token
			this.hostName = 'http://119.23.72.156:8700/execute'
			delete content.access_token
        }else{
            this.headers.accessToken = ''
            this.hostName = 'http://119.23.72.156:8700/login/bigScreen'
		}
		
		// console.log(content, 9999999)
        let options = {
            url: this.hostName,
            method: 'POST',
            headers: this.headers,  
            form: content,
        }
        request.post(options, postFunction);
    }
    /**
     * 大屏登录
     * @param {Function} cb 回调方法
     */
    login(cb) {
        let options = {
            url: this.hostName + '/login/bigScreen',
            method: 'POST',
            headers: this.headers,  
            form: { 
                grant_type: 'password',
                auth_type: 'bigScreen',
                loginKey: new Buffer('bigScreenToken' + new Date().getTime()).toString('base64')
            },
        }
        request.post(options, () => {

        });
    }
}
module.exports = http;